package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.SportsDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Food;
import com.itheima.pojo.Sports;
import com.itheima.service.SportsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = SportsService.class)
@Transactional
public class SportsServiceImpl implements SportsService {
    @Autowired
    private SportsDao sportsDao;

    @Override//分页查询
    public PageResult findPage(QueryPageBean queryPageBean) {
        Integer pageSize = queryPageBean.getPageSize();
        Integer currentPage = queryPageBean.getCurrentPage();
        PageHelper.startPage(currentPage, pageSize);
        String queryString = queryPageBean.getQueryString();
        Page<Sports> page = sportsDao.findByCondition(queryString);
        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override//批量添加
    public void addList(List<Sports> sportsList) {
        for (Sports sports : sportsList) {
            sportsDao.add(sports);
        }
    }

    @Override//单项添加
    public void add(Sports sports) {
        sportsDao.add(sports);
    }

    @Override//删除
    public void delete(Integer id) {
        sportsDao.delete(id);
    }

    @Override//修改
    public void edit(Sports sports) {
        sportsDao.edit(sports);
    }


    //    public Sports findById(Integer id) {
//        return  sportsDao.findById(id);
//    }
    @Override
    public List<Sports> findAll() {
        return sportsDao.findAll();
    }
}
